<template>
  <div class="app">
    <div class="nav">
      <div>
        <img
          src="https://s0.meituan.net/bs/myfe/canary/file/asgard/images/logo@3x.png"
          alt=""
        />
      </div>
      <div>
        <span class="f14 mr10">发现最新最热电影</span>
        <span class="f16">打开APP></span>
      </div>
    </div>
    <div class="flx nav_box bge7 fcff">
      猫眼
      <img
        src="https://p0.meituan.net/scarlett/f05f61e7a8f3f45fd071c068d7a26870356.png"
        alt=""
      />
    </div>
    <div class="content" v-for="(item, index) in list" :key="index">
      <div class="content-img">
        <img @click="initVideo(index)" :src="item.images[0].url" alt="" />
        <div class="title">{{ item.title }}</div>
        <div class="bottom">
          <img
            src="https://p1.meituan.net/moviemachine/bb79fd8a7de324b5d68dd72a887e4ee8278658.png"
            alt=""
          />
          <div class="user-name">{{ item.user.nickName }}</div>
          <img
            src="https://p1.meituan.net/moviemachine/5377c2c03dacf20b6e286e3e72dd57911272.png"
            alt=""
          />
          <div class="like-count">{{ item.upCount }}</div>
        </div>
      </div>
    </div>
    <div class="test_two_box" v-if="show" @click="go">
      <video @click.stop="" id="myVideo" class="video-js">
        <source :src="videoUrl" type="video/mp4" />
      </video>
    </div>
  </div>
</template>

<script>
// 引入axios对象
import axios from 'axios'
// axios.defaults.baseURL ="http://localhost:3000/api"
axios.interceptors.response.use(
  (response) => {
    return  response;
  },
  (error) => {
    return Promise.reject(error);
  }
);
export default {
  data() {
    return {
      list:[],
       typeactive: "0",
      videoUrl: "",
      show: false,
    };
  },
 methods:{
    //发起网络请求
    //  getBegin(){
    // const url = '/list.json?cors=T&uuid=57C72C00353D11EB89D605B4275B36B67C83404ACDAC496281E5C2BEC96423CE&channelId=4&feedChannelId=105&timestamp=1607231372769&offset=10'
    // axios.get(url).then((res)=>{
    //   console.log(res.data.feeds[0].shareInfo);
    // })
    //  },

     getBegin() {
      const url =
        "/api/list.json?uuid=57C72C00353D11EB89D605B4275B36B67C83404ACDAC496281E5C2BEC96423CE&channelId=4&feedChannelId=105&timestamp=1607310796498&offset=10";
      axios.get(url).then((res) => {
        // console.log(res);
        this.list = res.feeds;
        // console.log(this.list[0].images);
      });
    },
     initVideo(index) {
      //初始化视频方法
      // console.log(index);
      // console.log(this.list[index].video.url);
      this.show = true;
      this.videoUrl = this.list[index].video.url;
      setTimeout(() => {
         let myPlayer = this.$video(myVideo, {
        //确定播放器是否具有用户可以与之交互的控件。没有控件，启动视频播放的唯一方法是使用autoplay属性或通过Player API。
        controls: true,
        //自动播放属性,muted:静音播放
        autoplay: "",
        //建议浏览器是否应在<video>加载元素后立即开始下载视频数据。
        preload: "auto",
        //设置视频播放器的显示宽度（以像素为单位）
        width: "375px",
        //设置视频播放器的显示高度（以像素为单位）
        height: "200px",
      });

      }, 500);

    },
    go() {
this.$router.push('./video');//要跳转的界面
    }
  },

  mounted(){
    this.getBegin();
  },
  created() {
    //发起网络请求

    // axios.get(url).then(res=>{console.log(res),console.log(res.data.data)} )
    // console.log("1111111111111111");
  },
};
</script>
<style>
.video-js .vjs-big-play-button {
  left: 138px !important;
  top: 73px !important;
}
</style>
<style lang="scss" scoped>
.f14 {
  font-size: 14px;
}
.mr10 {
  margin-right: 10px;
}
.f16 {
  font-size: 16px;
}
.bge7 {
  background: #e54847;
}
.flx {
  display: flex;
  justify-content: center;
  align-items: center;
}
.nav {
  display: flex;
  box-sizing: border-box;
  width: 100%;
  padding: 10px 16px;
  align-items: center;
  justify-content: space-between;
  img {
    width: 94px;
  }
  .mr10 {
    margin-right: 10px;
  }
}
.nav_box {
  height: 48px;
  position: relative;
  img {
    width: 20px;
    position: absolute;
    right: 20px;
    top: 14px;
  }
}
.content-img {
  border: 1px solid #ffff;
  width: 185px;
  height: 300px;
  background: rgba(0, 0, 0, 0.6);
  position: relative;
  // background: url(http://p1.meituan.net/movie/d26c5508d52ca6cece24e33f3932e54216743.jpg)no-repeat;
  background-position: 50%;
  float: left;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  img {
    width: auto;
    height: 300px;
  }
  .title {
    font-size: 14px;
    position: absolute;
    bottom: 46px;
    margin: 0 8px;
    color: #ffffff;
    overflow: hidden;
  }
  .bottom {
    display: flex;
    align-items: center;
    font-size: 13px;
    bottom: 22px;
    position: absolute;
    margin: 0 6px;
    color: red;
    img {
      width: 21.5px;
      height: 21.5px;
    }
  }
  .test_two_box {
    width: 100%;
    height: 100vh;
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
  }
}
</style>
